/**
 * 定义分钟数据模块
 */
(function(window, angular, undefined){
	var module = angular.module('water.apps.WasteGas.ReportData.displaceStatistics.minuteDataManager', ['water.apps.common.report.reportBase','water.entity.monitorData']);
	
	module.controller('displaceStatisticsMinuteController',function($rootScope,$scope,$controller,$monitorDataService){

		var control = $controller("commonReportController",{$scope:$scope});
		
		$scope.dataAPIName = "minuteListGetter";
		$scope.dataExportAPIName = "exportMinExcel";
		/**
		 * 组合是否显示行数
		 */
		$scope.parmListNew=[];
		/**
		 * 数据项
		 */
		$scope.dataType=[];
		/**
		 * 数据主键集合
		 */
		$scope.keys = [];
		/**
		 * 查询报表数据
		 * 逻辑是，根据查询条件构建数据查询器，这个查询器就提供了分页功能
		 * 如果条件没有变化，就拿这个查询器进行上一页下一页操作
		 * 如果条件有变化，就重新初始化这个查询器
		 */
		$scope.getReport = function(queryObject){
			if(!$scope.dataAPIName){
				$scope.dataAPIName = "realTimeListGetter";
			}
			$scope.parmList = $scope.selectedModel.parmToCheckList;
			$scope.parmListNew=[];
			$scope.dataType=[];
			for(var i=0;i<$scope.parmList.length;i++){
				var parm=$scope.parmList[i];
				if(parm.name=="01"||parm.name=="02"||parm.name=="03"||parm.name=="04"||parm.name=="06"||parm.name=="08") {
					parm.colspan=2;
					$scope.dataType.push("实测值");
					$scope.dataType.push("折算值");
				}
				else{
					parm.colspan=1;
					$scope.dataType.push("实测值");
				}
				$scope.parmListNew.push(parm);
			}
			$scope.parmList=$scope.parmListNew;
			
			/**
			 * 获取日期分页的实时数据查询器，方便日期分页查询
			 * 页面上可以直接调用该对象的分页方法
			 */
			$scope.dataGetter = $monitorDataService[$scope.dataAPIName](queryObject,function(data){
				$scope.data = data;
				
				$scope.keys = [];
				$scope.stdKeys = [];
				for(var i=0;i<$scope.parmList.length;i++){
					var obj = $scope.parmList[i];
					if(obj.name=="01"||obj.name=="02"||obj.name=="03"||obj.name=="04"||obj.name=="06"||obj.name=="08") {
						$scope.keys.push("AVG_"+obj.name);
						$scope.keys.push("ZS_AVG_"+obj.name);
						$scope.stdKeys.push("RTD_"+obj.name);
						$scope.stdKeys.push("ZS_"+obj.name);
					}
					else{
						$scope.keys.push("AVG_"+obj.name);
						$scope.stdKeys.push("RTD_"+obj.name);
					}
				}
				/**
				 * 如果没有数据，直接启动窗口冻结，不然需要等很久
				 */
				if($scope.freezeGrid && data.data.length < 1){
					$scope.freezeGrid.freezeGridWithoutWait();
				}
			});
			$scope.dataGetter.nextPage();
			
		};
		/**
		 * 获取查询参数
		 * forExcel 是否用于导出
		 */
		$scope.getQueryObject = function(forExcel){
			var queryDate = $scope.queryDate;
			var startTime =queryDate + " " + $scope.startHour + ":00:00";
			var endTime = queryDate + " " + $scope.endHour + ":00:00";
			var parmsStr = $scope.selectedModel.parmToChecksStr;
			var queryObject = {
					"MN":$scope.selectedModel.MN,
					"PARMS":parmsStr,
					"START":startTime,
					"END":endTime,
					"EXPORT":forExcel
				};
			return queryObject;
		};
		$scope.getDisplaceRadio = function() {
			var minRadio=$("#mt").prop("checked");
			var hourRadio=$("#hr").prop("checked");
			var dayRadio=$("#dy").prop("checked");
			var monthRadio=$("#month").prop("checked");
			
			if(minRadio||hourRadio||dayRadio||monthRadio){
				$("#displaceStatistics").prop("checked","true");
			}	
		};
		$scope.getDisplaceRadio();
	});
}(window, angular));	